<meta charset="utf-8">
(#) Notification Icon Compatibility

!!! WARNING: Notification Icon Compatibility
   This is a warning.

Id
:   `NotificationIconCompatibility`
Summary
:   Notification Icon Compatibility
Severity
:   Warning
Category
:   Correctness
Platform
:   Android
Vendor
:   Android Open Source Project
Feedback
:   https://issuetracker.google.com/issues/new?component=192708
Since
:   3.2.0 (September 2018)
Affects
:   Kotlin and Java files, manifest files and resource files
Editing
:   This check can *not* run live in the IDE editor
Implementation
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/IconDetector.java)
Tests
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IconDetectorTest.java)

Notification icons should define a raster image to support Android
versions below 5.0 (API 21). Note that the way Lint decides whether an
icon is a notification icon is based on the filename prefix `ic_stat_`.
This corresponds to the naming convention documented in
https://d.android.com/r/studio-ui/designer/material/iconography.

(##) Example

Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
res/drawable/icon1.xml:Warning: Notification icon icon1 has to have a
raster image to support Android versions below 5.0 (API 21)
[NotificationIconCompatibility]
0 errors, 1 warnings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here are the relevant source files:

`src/test/pkg/NotificationTest.java`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers
package test.pkg;

import android.app.Notification;
import android.app.Notification.Builder;
import android.content.Context;
import android.graphics.Bitmap;

@SuppressWarnings({ "deprecation", "unused", "javadoc" })
class NotificationTest {
    public void test1() {
        Notification notification = new Notification(R.drawable.icon1, "Test1", 0);
    }

    public void test2() {
        int resource = R.drawable.icon2;
        Notification notification = new Notification(resource, "Test1", 0);
    }

    public void test3() {
        int icon = R.drawable.icon3;
        CharSequence tickerText = "Hello";
        long when = System.currentTimeMillis();
        Notification notification = new Notification(icon, tickerText, when);
    }

    public void test4(Context context, String sender, String subject, Bitmap bitmap) {
        Notification notification = new Notification.Builder(context)
                .setContentTitle("New mail from " + sender.toString())
                .setContentText(subject).setSmallIcon(R.drawable.icon4)
                .setLargeIcon(bitmap).build();
    }

    public void test5(Context context, String sender, String subject, Bitmap bitmap) {
        Notification notification = new Builder(context)
                .setContentTitle("New mail from " + sender.toString())
                .setContentText(subject).setSmallIcon(R.drawable.icon5)
                .setLargeIcon(bitmap).build();
    }
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/drawable/icon1.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;vector/&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can also visit the
[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IconDetectorTest.java)
for the unit tests for this check to see additional scenarios.

The above example was automatically extracted from the first unit test
found for this lint check, `IconDetector.testNotificationIconCompatibility`.
To report a problem with this extracted sample, visit
https://issuetracker.google.com/issues/new?component=192708.

(##) Suppressing

You can suppress false positives using one of the following mechanisms:

* Using a suppression annotation like this on the enclosing
  element:

  ```kt
  // Kotlin
  @Suppress("NotificationIconCompatibility")
  fun method() {
     problematicStatement()
  }
  ```

  or

  ```java
  // Java
  @SuppressWarnings("NotificationIconCompatibility")
  void method() {
     problematicStatement();
  }
  ```

* Using a suppression comment like this on the line above:

  ```kt
  //noinspection NotificationIconCompatibility
  problematicStatement()
  ```

* Adding the suppression attribute
  `tools:ignore="NotificationIconCompatibility"` on the problematic
  XML element (or one of its enclosing elements). You may also need to
  add the following namespace declaration on the root element in the
  XML file if it's not already there:
  `xmlns:tools="http://schemas.android.com/tools"`.

  ```xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;manifest xmlns:tools="http://schemas.android.com/tools"&gt;
      ...
      &lt;application tools:ignore="NotificationIconCompatibility" .../&gt;
    ...
  &lt;/manifest&gt;
  ```

* Using a special `lint.xml` file in the source tree which turns off
  the check in that folder and any sub folder. A simple file might look
  like this:
  ```xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;lint&gt;
      &lt;issue id="NotificationIconCompatibility" severity="ignore" /&gt;
  &lt;/lint&gt;
  ```
  Instead of `ignore` you can also change the severity here, for
  example from `error` to `warning`. You can find additional
  documentation on how to filter issues by path, regular expression and
  so on
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).

* In Gradle projects, using the DSL syntax to configure lint. For
  example, you can use something like
  ```gradle
  lintOptions {
      disable 'NotificationIconCompatibility'
  }
  ```
  In Android projects this should be nested inside an `android { }`
  block.

* For manual invocations of `lint`, using the `--ignore` flag:
  ```
  $ lint --ignore NotificationIconCompatibility ...`
  ```

* Last, but not least, using baselines, as discussed
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).

<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>